package model;

import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class AIBar extends Bar
{
        private boolean easy;
        private double coeff;
        private final double COEFF_E = 0.001;
        private final double COEFF_H = 0.002;
        
        public AIBar()
        {
                super();
                easy = true;
                barType = "AI";
                speedState = 1;
                coeff = COEFF_E;
                
                try{
                        image = ImageIO.read(new File("AIBar.png"));
                } catch(IOException e){ 
                }
        }
        
        public AIBar(boolean diff)
        {
                super();
                easy = diff;
                barType = "AI";
                speedState = 1;
                coeff = COEFF_E;
                
                try{
                        image = ImageIO.read(new File("AIBar.png"));
                } catch(IOException e){ 
                }
        }
        
        public void setCoeff(double c)
        {
                coeff = c;
        }
        
        public double getCoeff()
        {
                return coeff;
        }
        
        public boolean getDifficulty()
        {
                return easy;
        }
                
        public void setDifficulty(boolean diff)
        {
                easy = diff;
                
                if(easy)
                        coeff = COEFF_E;
                else
                        coeff = COEFF_H;
        }
        
        public void update(Vector2 vect)
        {
                if(easy)
                {
                        this.setComponentX(vect.getComponentX());
                        
                        this.setX(this.getX() + (this.getComponentX()*coeff));
                }       
                else
                {                       
                        if(vect.getX() > this.getX())
                        {
                                setX(getX() + Math.abs(vect.getComponentX()) * coeff);
                                setComponentX(20);
                        }
                        else
                        {
                                setX(getX() - Math.abs(vect.getComponentX()) * coeff);
                                setComponentX(-20);
                        }
                }
                                
        }

}